package com.yunkaweilai.android.view.dialog.member;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.github.lazylibrary.util.StringUtils;
import com.yunkaweilai.android.R;
import com.yunkaweilai.android.interfaces.DialogMemberPayInterface;
import com.yunkaweilai.android.view.MyToast;

/**
 * 输入支付密码
 * Created by Administrator on 2016/12/22 0022.
 */

public class MemberPassDialog extends Dialog {
    ImageView idImgClose;
    TextView idTvRight;
    EditText idEdtTypeName;
    private Context context;
    private TextView idTvTitle;
    private CheckBox idCheckPass;
    private DialogMemberPayInterface dialogMemberPayInterface;

    public MemberPassDialog(Context context, DialogMemberPayInterface dialogMemberPayInterface) {
        super(context,R.style.dialog);
        this.context = context;
        this.dialogMemberPayInterface = dialogMemberPayInterface;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_member_pay);
        idImgClose = (ImageView) findViewById(R.id.id_img_close);
        idTvRight = (TextView) findViewById(R.id.id_tv_right);
        idEdtTypeName = (EditText)findViewById(R.id.id_edt_type_name);
        idCheckPass = ((CheckBox) findViewById(R.id.id_check_pass));

        idImgClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        idTvRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!StringUtils.isEmpty(idEdtTypeName.getText().toString())) {
                    dialogMemberPayInterface.passPay(idEdtTypeName.getText().toString());
                    dismiss();
                } else {
                    MyToast.showShortToast(context, "还未输入支付密码!");
                }
            }
        });

        idCheckPass.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                // TODO Auto-generated method stub
                if (isChecked) {
                    //如果选中，显示密码
                    idEdtTypeName.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
                } else {
                    //否则隐藏密码
                    idEdtTypeName.setTransformationMethod(PasswordTransformationMethod.getInstance());
                }
            }
        });
    }

}
